// ml:run = $bin < B-large.in > b-large.out
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>

using ll = long long;

int const maxn = 200;
bool vis[maxn];
ll r[maxn], b[maxn];
ll map[maxn][maxn];
int n;

struct data
{
    ll cost; int end;
};

bool operator<(data const& a, data const& b)
{
    return a.cost > b.cost;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        std::cin >> n;
        for (int i = 0; i < n; i++) std::cin >> r[i];
        for (int i = 0; i < n; i++) std::cin >> b[i];

        for (int i = 0; i < n; i++) vis[i] = false;

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                map[i][j] = std::min(r[i] ^ b[j], r[j] ^ b[i]);

        std::priority_queue<data> pq;
        vis[0] = true;
        for (int i = 1; i < n; i++) pq.push({map[0][i], i});

        ll ans = 0;
        for (int i = 1; i < n; i++) {
            while (vis[pq.top().end]) pq.pop();

            auto now = pq.top(); pq.pop();
            vis[now.end] = true;
            ans += now.cost;

            for (int j = 1; j < n; j++)
                if (!vis[j])
                    pq.push({map[now.end][j], j});
        }

        std::cout << ans << "\n";
    }
}

